<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>添加权限</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var password = Ext.create('Ext.form.field.Text', {
          fieldLabel: '新密码',
          name: 'password',
          id:'pass',
          inputType: 'password',
          allowBlank: false,
          minLenght: 6,
          blankText: "新密码不能为空",
          anchor: '90%'
        })

        var rPassword = Ext.create('Ext.form.field.Text', {
          fieldLabel: '重复新密码',
          name: 'password',
          inputType: 'password',
          allowBlank: false,
          blankText: "重复新密码不能为空",
          minLenght: 6,
          anchor: '90%',
          vtype: 'password',
          initialPassField: 'pass'
        })
               
        //提交按钮
        var submitButton = Ext.create('Ext.Button', {
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            if (password.getValue() < 6){
              Ext.MessageBox.show({
                title: '消息',
                msg: "密码长度不能小于6！",
                buttons: Ext.MessageBox.OK,
                icon: Ext.MessageBox.WARNING
              });
              return;
            }
            submitButton.setDisabled(true);
            if (changePasswordFormPanel.form.isValid()) {
              changePasswordFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: '密码修改成功！',
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.INFO
                    });
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  submitButton.enable();
                },
                failure: function(result, request){
                  submitButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              submitButton.enable();
              
            }
          }
        })
        
        var changePasswordFormPanel = Ext.create('Ext.form.Panel', {
          fieldDefaults: {
            labelWidth: 75,
            labelAlign: 'right'
          },
          width: 300,
          buttonAlign: 'center',
          frame : true,
          url: '/admin/changePassword',
          method: 'GET',
          items: [password,rPassword],
          buttons: [submitButton]
        });
        changePasswordFormPanel.render('change_password_form');
      })
    </script>
    <div id="change_password_form"></div>
  </body>
</html>